# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from datetime import datetime, timedelta

from odoo import fields, http
from odoo.exceptions import AccessError
from odoo.http import request
from odoo import release
from odoo import http
from odoo.http import content_disposition, dispatch_rpc, request, \
                      serialize_exception as _serialize_exception
class WebSettingsDashboard002(http.Controller):

    @http.route('/web_settings_dashboard002/data', type='json', auth='user')
    def web_settings_dashboard_data002(self, **kw):
        return {'uid002': request.session.uid002,}
    @http.route('/web_report/', auth='public', website=True)		
    def sys_test(self):
        values={}
        values['server_mac'] = ''
        values['residual_service_time'] = "0"       
        return request.render('web_report.index2', values)  
        
    @http.route('/web/web_report/res_partner',type='http', auth="public", methods=['POST'], csrf=False)
    def res_partner(self, debug=False,**kw):
        result=[]      
        lselfs= http.request.env["mybase.fhorgan"].search([])
        for odoj in lselfs:		
            result.append({
            'id':odoj.id,
            'name':str(odoj.fhname) or "False",
            })    

        print(str(result))             
        return str(result)

    @http.route('/web/web_report',type='http', auth="public", methods=['POST'], csrf=False)		
    def resource_report(self, debug=False,**kw):
 
        dep_year=kw.get('dep_year')
        dep_data=kw.get('dep_data')
        print('-dep_year-',dep_year)
        print('--dep_data--',dep_data)        
         
                       
        return str([{
        "fhcategory":['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
        "fhseries1":[
        self.sum_fhmoney_resource_report(dep_year,"01",dep_data,"0"), 
        self.sum_fhmoney_resource_report(dep_year,"02",dep_data,"0"),
        self.sum_fhmoney_resource_report(dep_year,"03",dep_data,"0"),
        self.sum_fhmoney_resource_report(dep_year,"04",dep_data,"0"),
        self.sum_fhmoney_resource_report(dep_year,"05",dep_data,"0"),
        self.sum_fhmoney_resource_report(dep_year,"06",dep_data,"0"),
        self.sum_fhmoney_resource_report(dep_year,"07",dep_data,"0"),
        self.sum_fhmoney_resource_report(dep_year,"08",dep_data,"0"),
        self.sum_fhmoney_resource_report(dep_year,"09",dep_data,"0"),
        self.sum_fhmoney_resource_report(dep_year,"10",dep_data,"0"),
        self.sum_fhmoney_resource_report(dep_year,"11",dep_data,"0"),
        self.sum_fhmoney_resource_report(dep_year,"12",dep_data,"0"),
        ],
        "fhseries2":[
        self.sum_fhreality_money_resource_report(dep_year,"01",dep_data,"0"), 
        self.sum_fhreality_money_resource_report(dep_year,"02",dep_data,"0"), 
        self.sum_fhreality_money_resource_report(dep_year,"03",dep_data,"0"), 
        self.sum_fhreality_money_resource_report(dep_year,"04",dep_data,"0"), 
        self.sum_fhreality_money_resource_report(dep_year,"05",dep_data,"0"), 
        self.sum_fhreality_money_resource_report(dep_year,"06",dep_data,"0"), 
        self.sum_fhreality_money_resource_report(dep_year,"07",dep_data,"0"), 
        self.sum_fhreality_money_resource_report(dep_year,"08",dep_data,"0"), 
        self.sum_fhreality_money_resource_report(dep_year,"09",dep_data,"0"), 
        self.sum_fhreality_money_resource_report(dep_year,"10",dep_data,"0"), 
        self.sum_fhreality_money_resource_report(dep_year,"11",dep_data,"0"), 
        self.sum_fhreality_money_resource_report(dep_year,"12",dep_data,"0"), 
        ],
        "fhseries3":[
        self.sum_fhmoney_resource_report(dep_year,"01",dep_data,"1"), 
        self.sum_fhmoney_resource_report(dep_year,"02",dep_data,"1"),
        self.sum_fhmoney_resource_report(dep_year,"03",dep_data,"1"),
        self.sum_fhmoney_resource_report(dep_year,"04",dep_data,"1"),
        self.sum_fhmoney_resource_report(dep_year,"05",dep_data,"1"),
        self.sum_fhmoney_resource_report(dep_year,"06",dep_data,"1"),
        self.sum_fhmoney_resource_report(dep_year,"07",dep_data,"1"),
        self.sum_fhmoney_resource_report(dep_year,"08",dep_data,"1"),
        self.sum_fhmoney_resource_report(dep_year,"09",dep_data,"1"),
        self.sum_fhmoney_resource_report(dep_year,"10",dep_data,"1"),
        self.sum_fhmoney_resource_report(dep_year,"11",dep_data,"1"),
        self.sum_fhmoney_resource_report(dep_year,"12",dep_data,"1"),
        ],
        "fhseries4":[
        self.sum_fhreality_money_resource_report(dep_year,"01",dep_data,"1"), 
        self.sum_fhreality_money_resource_report(dep_year,"02",dep_data,"1"), 
        self.sum_fhreality_money_resource_report(dep_year,"03",dep_data,"1"), 
        self.sum_fhreality_money_resource_report(dep_year,"04",dep_data,"1"), 
        self.sum_fhreality_money_resource_report(dep_year,"05",dep_data,"1"), 
        self.sum_fhreality_money_resource_report(dep_year,"06",dep_data,"1"), 
        self.sum_fhreality_money_resource_report(dep_year,"07",dep_data,"1"), 
        self.sum_fhreality_money_resource_report(dep_year,"08",dep_data,"1"), 
        self.sum_fhreality_money_resource_report(dep_year,"09",dep_data,"1"), 
        self.sum_fhreality_money_resource_report(dep_year,"10",dep_data,"1"), 
        self.sum_fhreality_money_resource_report(dep_year,"11",dep_data,"1"), 
        self.sum_fhreality_money_resource_report(dep_year,"12",dep_data,"1"), 
        ]
        }])


    def sum_fhmoney_resource_report(self,dep_year,dep_m,dep_data="1",fhnature="0"):
        result=0 
        domain=[('fhplanned_time','like',dep_year+"-"+dep_m),('fhorgan','=',int(dep_data)),('fhnature','=',fhnature)]  
        print('domain:',domain)    
        lselfs= http.request.env["cfarmc_contract.fhcapital_plan"].search(domain)        
        for odoj in lselfs:
            if 1==1:
                result=result+ odoj.fhmoney   
        print(str(result)) 
        return str(result)    

    def sum_fhreality_money_resource_report(self,dep_year,dep_m,dep_data="1",fhnature="0"):
        result=0 
        domain=[('fhplanned_time','like',dep_year+"-"+dep_m),('fhorgan','=',int(dep_data)),('fhnature','=',fhnature)]  
        print('domain:',domain)    
        lselfs= http.request.env["cfarmc_contract.fhcapital_plan"].search(domain)        
        for odoj in lselfs:
            if 1==1:
                result=result+ odoj.fhreality_money   
        print(str(result)) 
        return str(result)    
        